module Helpers

using Lazy

function issome(x :: T) :: Bool where {T}
  !=(nothing, x)
end
export issome

function or(a, b)
  issome(a) ? a : b
end
function or(b)
  a -> or(a, b)
end
export or

function debug(title, x)
  @debug title x
end
function debug(title)
  x -> debug(title, x)
end
export debug

function has_and_eq(dict, key, val)
  if haskey(dict, key)
    dict[key] == val
  else
    false
  end
end
export has_and_eq

function doon(f :: Function)
  x -> begin
    f(x)
    x
  end
end
export doon

function when_some(f, x)
  if issome(x)
    f(x)
  else
    nothing
  end
end
function when_some(f)
  x -> when_some(f, x)
end
export when_some

function partial(f,a...)
  ( (b...) -> f(a...,b...) )
end
export partial

end
